package com.tianhui.consignortwofei.other.auth.recognition.recognitionResultProcess;

import android.text.TextUtils;

import com.fgs.common.utils.DateUtil;
import com.fgs.common.utils.LogUtil;
import com.tianhui.consignortwofei.mvp.model.enty.BusinessLicenseInfo;
import com.tianhui.consignortwofei.mvp.model.enty.ocrResult.businessLicense.BusinessLicenseResult;
import com.xuexiang.xutil.net.JsonUtil;

/**
 * @author fgs
 * @date 2020/11/16
 * @description
 **/
public class BusinessLicenseOcrResultProcess {

    public BusinessLicenseInfo getBusinessLicenseOcrResult(BusinessLicenseResult result) {
        BusinessLicenseInfo businessLicenseInfo = new BusinessLicenseInfo();

        if (result == null) {
            return businessLicenseInfo;
        }
        if (result.getStartDate() != null) {
            String string = result.getStartDate().getWords();
            if (!TextUtils.isEmpty(string)) {
                businessLicenseInfo.startDate = dateFormat(string);
            }
            LogUtil.print("获取成立日期", businessLicenseInfo.startDate);
        }
        if (result.getEndDate() != null) {
            String string = result.getEndDate().getWords();
            businessLicenseInfo.endDate = dateFormat(string);
            LogUtil.print("获取有效日期至", businessLicenseInfo.endDate);
        }
        //社会信用代码
        if (result.getSocialCreditCode() != null) {
            String socialCreditCode = result.getSocialCreditCode().getWords();
            businessLicenseInfo.socialCreditCode = socialCreditCode;
            LogUtil.print("社会信用代码", socialCreditCode);
        }
        //单位名称
        if (result.getUnitName() != null) {
            String unitName = result.getUnitName().getWords();
            businessLicenseInfo.unitName = unitName;
            LogUtil.print("单位名称", unitName);
        }
        //法定代表人
        if (result.getLegalPerson() != null) {
            String legalPerson = result.getLegalPerson().getWords();
            businessLicenseInfo.legalPerson = legalPerson;
            LogUtil.print("法定代表人", legalPerson);
        }
        //住址
        if (result.getAddress() != null) {
            String address = result.getAddress().getWords();
            businessLicenseInfo.address = address;
            LogUtil.print("住址", address);
        }
        //类型
        if (result.getType() != null) {
            String type = result.getType().getWords();
            businessLicenseInfo.type = type;
            LogUtil.print("类型", type);
        }

        //经营范围
        if (result.getBusinessNature() != null) {
            String businessNature = result.getBusinessNature().getWords();
            businessLicenseInfo.businessNature = businessNature;
            LogUtil.print("经营范围", businessNature);
        }
        //注册资本
        if (result.getRegisteredCapital() != null) {
            String registeredCapital = result.getRegisteredCapital().getWords();
            businessLicenseInfo.registeredCapital = registeredCapital;
            LogUtil.print("注册资本", registeredCapital);
        }
        LogUtil.print("businessLicenseInfo", JsonUtil.toJson(businessLicenseInfo));
        return businessLicenseInfo;
    }

    public String dateFormat(String date) {
        return DateUtil.validDateFormat(date, "yyyyMMdd");
    }
}
